package suites.tween {
	import org.flexunit.asserts.assertEquals;
	import org.flexunit.asserts.assertTrue;
	import org.splink.library.queue.QEvent;
	import org.splink.library.tween.IQTween;
	import org.splink.library.tween.QTween;
	import org.splink.library.tween.QTweenConst;
	import org.splink.library.tween.sprop.ColorProp;
	import org.splink.library.tween.sprop.ISpecialProp;

	import flash.events.Event;

	/**
	 * @author Max Kugland
	 */
	public class TweenOverrideTest extends AbstractTweenTest {

		[Test(async)]
		public function testSingleOverride() : void {
			var fnc : Function = handleAsync(500);
			var flag : Boolean = true;
			_tween.add(QTweenConst.ALPHA, 0).duration(200);
			_tween.register(QEvent.PROGRESS, function(e : QEvent):void {
				if(e.progress.percent > 50 && flag) {
					flag = false;
					assertTrue(_target.alpha != 0);					assertTrue(_target.alpha != 1);
					
					var t : IQTween = new QTween(_target).add(QTweenConst.ALPHA, 1).duration(200);
					t.register(QEvent.COMPLETE, function(e : QEvent) : void {
						assertEquals(1, _target.alpha);
						fnc(new Event(Event.COMPLETE));
					});
					t.start();
				}
			});
			
			assertEquals(1, _target.alpha);
			_tween.start();
		}
		
		[Test(async)]
		public function testSingleSpecialPropOverride() : void {
			var fnc : Function = handleAsync(500);
			var flag : Boolean = true;
			
			var p : ISpecialProp = new ColorProp(_target);
			
			_tween.add(ColorProp.COLOR, 0xff0000, NaN, p).duration(200);
			_tween.register(QEvent.PROGRESS, function(e : QEvent):void {
				if(e.progress.percent > 50 && flag) {
					flag = false;
					assertTrue(_target.transform.colorTransform.color != 0);
					assertTrue(_target.transform.colorTransform.color != 0xff0000);
					
					var t : IQTween = new QTween(_target).add(ColorProp.COLOR, 0x00ffff, NaN, p).duration(200);
					t.register(QEvent.COMPLETE, function(e : QEvent) : void {
						assertEquals(0x00ffff, _target.transform.colorTransform.color);
						fnc(new Event(Event.COMPLETE));
					});
					t.start();
				}
			});
			
			assertEquals(0, _target.transform.colorTransform.color);
			_tween.start();
		}
	}
}
